﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using Microsoft.Devices;
using System.IO;

namespace ASPItalia.ModelVirtualCasting.WP7
{
    public partial class DetailsPage : PhoneApplicationPage
    {
        private string uri;

        public DetailsPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string fileName = this.NavigationContext.QueryString["fn"];
			this.uri = String.Format("http://modelvc.local/Images/{0}", fileName);
            this.img.Source = new BitmapImage(new Uri(uri));

            using (Stream thumb = Application.GetResourceStream(
                      new Uri("Background.png", UriKind.Relative)).Stream)
            {
                // l'immagine deve essere 173x173
                MediaHistoryItem item = new MediaHistoryItem
                {
                    Title = "Modella xx",
                    Source = "Visualizza",
                    ImageStream = thumb,
                };

                // aggiungo informazioni di contesto
                item.PlayerContext.Add("uri", uri);

                // imposto su "now playing"
                MediaHistory.Instance.NowPlaying = item;

                thumb.Seek(0, SeekOrigin.Begin);

                // aggiungo all'history
                MediaHistory.Instance.WriteRecentPlay(item);

                thumb.Seek(0, SeekOrigin.Begin);

                // aggiungo alle novità
                MediaHistory.Instance.WriteAcquiredItem(item);
            }
        }
    }
   
}